package com.leet.code.simple_array;

/**
 * @description:
 * @author: WYG
 * @time: 2020/11/26 18:14
 */

public class DominantIndex {
    public int dominantIndex(int[] nums) {
        int max = nums[0];
        int res = 0;
        for (int i = 1; i < nums.length; i++) {
            if (max < nums[i]) {
                max = nums[i];
                res = i;
            }
        }
        boolean flag = true;
        for (int i = 0; i < nums.length; i++) {
            if (i != res && (max < nums[i] * 2)) {
                flag = false;
            }
        }
        return flag ? res : -1;
    }
}
